package o;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import java.util.ArrayList;
import java.util.Iterator;
import o.ewm.h;
import o.ewm.i;
import o.ewm.j;
import o.ewm.n;

public class ewg extends cku {
    private long ˊॱ;
    private long ͺ;
    private boolean ॱ = true;
    private ArrayList<String> ॱˊ;
    private CheckBox ॱᐝ;

    public static cku ˊ(Context context, String str, String str2, long j, ArrayList<String> arrayList, long j2) {
        try {
            cku o_ewg = new ewg();
            Bundle bundle = new Bundle();
            bundle.putString("tileContent", str);
            bundle.putString("content", str2);
            bundle.putLong("resumeTask", j);
            bundle.putStringArrayList("cancelPkgs", arrayList);
            bundle.putLong("clearSpace", j2);
            o_ewg.setArguments(bundle);
            return o_ewg;
        } catch (Exception e) {
            return new cku();
        }
    }

    public static void ॱ(final Context context, epj o_epj, final Class<?> cls, boolean z, String str) {
        Object obj = null;
        if (o_epj != null && context != null) {
            cku ॱ;
            if (cls != null && cls.isAssignableFrom(context.getClass())) {
                obj = 1;
                o_epj.ॱ(context.getString(n.ˊʾ));
            }
            Object obj2 = obj;
            if (z) {
                ॱ = ewh.ॱ(context, o_epj.ॱ(), o_epj.ˋ());
            } else {
                ॱ = cku.ˏ(context, cku.class, o_epj.ॱ(), o_epj.ˋ());
            }
            if (ॱ != null) {
                if (obj2 != null) {
                    ॱ.ˎ(-1, 8);
                }
                if (z) {
                    ॱ.ˎ(context);
                } else {
                    ॱ.ˋ(context, str + System.currentTimeMillis());
                }
                ॱ.ॱ(-2, o_epj.ˎ());
                ॱ.ॱ(-1, o_epj.ˏ());
                ॱ.ॱ(new cks() {
                    public void enableNetworking() {
                        context.startActivity(new Intent(context, cls));
                    }

                    public void upgrade() {
                    }

                    public void ˋ() {
                    }
                });
            }
        }
    }

    public Dialog onCreateDialog(Bundle bundle) {
        if (bundle != null) {
            this.ॱ = bundle.getBoolean("ck_enable");
        }
        return super.onCreateDialog(bundle);
    }

    public Builder ˋ(Context context) {
        Builder ˋ = super.ˋ(context);
        Bundle arguments = getArguments();
        if (arguments != null) {
            this.ˊॱ = arguments.getLong("resumeTask");
            this.ॱˊ = arguments.getStringArrayList("cancelPkgs");
            this.ͺ = arguments.getLong("clearSpace");
        }
        ˋ.setNegativeButton(null, null);
        ˋ.setPositiveButton(context.getString(n.ˊʾ), new OnClickListener(this) {
            final /* synthetic */ ewg ˊ;

            {
                this.ˊ = r1;
            }

            public void onClick(DialogInterface dialogInterface, int i) {
                if (this.ˊ.ॱ) {
                    Iterator it = this.ˊ.ॱˊ.iterator();
                    while (it.hasNext()) {
                        String str = (String) it.next();
                        try {
                            SessionDownloadTask ˎ = dvt.ˏ().ˎ(Long.parseLong(str));
                            if (ˎ != null) {
                                if (Logger.ˎ()) {
                                    Logger.ˏ("NoSpaceDialog", "cancel task, id:" + ˎ.ʾ() + ",pkg:" + str);
                                }
                                dkb.ˎ(ˎ);
                                ˎ.ˏ(0);
                                ˎ.ʽ(0);
                                dvt.ˏ().ˏ(ˎ.ʾ(), ˎ.ˊˊ(), 5);
                                synchronized (ˎ) {
                                    try {
                                        ˎ.notifyAll();
                                    } catch (Exception e) {
                                        Logger.e("NoSpaceDialog", "task notifyAll exception:" + e.getMessage());
                                    }
                                }
                            }
                        } catch (NumberFormatException e2) {
                            Logger.e("NoSpaceDialog", "NumberFormatException");
                        }
                    }
                    SessionDownloadTask ˎ2 = dvt.ˏ().ˎ(this.ˊ.ˊॱ);
                    if (ˎ2 != null) {
                        dvt.ˏ().ˎ(ˎ2);
                    }
                }
                this.ˊ.dismissAllowingStateLoss();
            }
        });
        ˋ.setView(ˋ(LayoutInflater.from(context)));
        return ˋ;
    }

    private View ˋ(LayoutInflater layoutInflater) {
        int size;
        View inflate = layoutInflater.inflate(h.ॱـ, null);
        View findViewById = inflate.findViewById(j.ʻʽ);
        this.ॱᐝ = (CheckBox) inflate.findViewById(j.ˊᐧ);
        this.ॱᐝ.setChecked(this.ॱ);
        findViewById.setOnClickListener(new View.OnClickListener(this) {
            final /* synthetic */ ewg ˊ;

            {
                this.ˊ = r1;
            }

            public void onClick(View view) {
                this.ˊ.ॱᐝ.toggle();
            }
        });
        TextView textView = (TextView) inflate.findViewById(j.ˊᶥ);
        if (this.ॱˊ != null) {
            size = this.ॱˊ.size();
        } else {
            size = 0;
        }
        textView.setText(ContentManager.getInstant().getContext().getResources().getQuantityString(i.ˈ, size, new Object[]{Integer.valueOf(size), epw.ˊ(this.ͺ)}));
        this.ॱᐝ.setOnCheckedChangeListener(new OnCheckedChangeListener(this) {
            final /* synthetic */ ewg ˊ;

            {
                this.ˊ = r1;
            }

            public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                this.ˊ.ॱ = z;
            }
        });
        return inflate;
    }

    public void onSaveInstanceState(Bundle bundle) {
        bundle.putBoolean("ck_enable", this.ॱ);
        super.onSaveInstanceState(bundle);
    }
}
